/**
 * 入参
 *
 */
import React, { PureComponent } from 'react';
import style from './index.less';
import { connect } from 'dva';
import DetailC from './myComps/detailC';
import TableListC from './myComps/tableListC';

class PortfolioDefinition extends PureComponent {
  state = {
    pageStatus: 1, //默认 1 列表页2详情页
    rootId: undefined, //组合详情id
  };
  UNSAFE_componentWillMount() {
    this.props.dispatch({
      type: 'portfolioDefinitionM/queryAprrovalUserList',
      payload: {},
    });
    this.props.dispatch({
      type: 'portfolioDefinitionM/queryOrderUserList',
      payload: {},
    });
  }
  componentWillUnmount() {
    this.props.dispatch({
      type: 'portfolioDefinitionM/setState',
      payload: {
        apprpvalUserList: [],
        orderUserList: [],
      },
    });
  }
  //点击关闭 切换到第一页
  onClose = () => {
    this.setState({
      pageStatus: 1,
    });
  };
  //进入组合详情页
  goDetail = (item) => {
    if (!item) return;
    this.setState({
      pageStatus: 2,
      rootId: item.id,
      rootItem: {
        name: item.portfolioName,
        value: item.portfolioCode,
        isInvestment: item.isInvestment || false,
        isExtra: item.isExtra, //是否有外部通道
        tradeMode: item.tradeMode, //交易模式
      },
    });
  };

  render() {
    const { pageStatus, rootId, rootItem } = this.state;
    return (
      <div className={style.portfolioDefinition} style={{ height: '100%' }}>
        <div style={{ display: pageStatus == 1 ? 'inherit' : 'none' }}>
          <TableListC goDetail={this.goDetail} />
        </div>
        {pageStatus == 2 && <DetailC onClose={this.onClose} rootId={rootId} rootItem={rootItem} />}
      </div>
    );
  }
}
export default connect(({ portfolioDefinitionM, userM: user, loading }) => ({
  portfolioDefinitionM,
  user,
  loading,
}))(PortfolioDefinition);
